from django.db import models
from django.contrib.auth.models import AbstractUser


# Create your models here.

class UserInfo(AbstractUser):
    role = models.ManyToManyField("Role", verbose_name="用户和角色的关系")
    token = models.CharField(verbose_name="token", max_length=164, default="")
    expires = models.DateTimeField(verbose_name="到期事件", blank=True, null=True)


class Role(models.Model):
    name = models.CharField(verbose_name="角色名称", max_length=32)
    menu = models.ManyToManyField("Menu", verbose_name="角色和菜单")


class Menu(models.Model):
    GENDER_CHOICES = (
        (u'1', u'目录'),
        (u'2', u'菜单'),
        (u'3', u'按钮'),
    )

    name = models.CharField(verbose_name="菜单名称", max_length=32)
    icon = models.CharField(verbose_name="菜单icon", max_length=32)
    url = models.CharField(verbose_name="请求地址", max_length=64)
    component = models.CharField(verbose_name="组件地址", max_length=64)
    type = models.CharField(verbose_name="类型", choices=GENDER_CHOICES, max_length=10)
    pid = models.IntegerField(verbose_name="菜单的父节点", max_length=255)
